package genedit.gui.propertyDialogs;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import genedit.gui.GMainFrame;
import genedit.model.graph.classModel.AssociationLink;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class AssociationLinkDialog  extends JDialog {
	
	protected JFrame parent;
	protected GMainFrame mf = GMainFrame.getInstance();
	protected AssociationLink linkAssociation;
	protected JButton btnOkDialog;
	protected PanelDetailAssociationLink panelAssociation;
	
	public AssociationLinkDialog(JFrame parent, AssociationLink link) {
		super(parent, true);
		
		linkAssociation = link;
		this.parent = parent;
		
		setTitle(linkAssociation.getName());		;
		setSize(mf.getWidth()/3, 2*mf.getHeight()/5);
		setLocationRelativeTo(parent);
		
		panelAssociation = new PanelDetailAssociationLink(linkAssociation);
		add(panelAssociation, BorderLayout.CENTER);
		
		JPanel panSouth = new JPanel();
		panSouth.setLayout(new BoxLayout(panSouth, BoxLayout.PAGE_AXIS));
		 btnOkDialog = new JButton(GMainFrame.getInstance().getResourceBundle().getString("btnOk"));
		 btnOkDialog.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
						linkAssociation.setName(panelAssociation.getTxtName().getText());
						linkAssociation.setMultiplicityStart((String)panelAssociation.getCmbMultiplicity1().getSelectedItem());
						linkAssociation.setMultiplicityEnd((String)panelAssociation.getCmbMultiplicity2().getSelectedItem());
						linkAssociation.setStartNavigable(panelAssociation.getChkNavigable1().isSelected());
						linkAssociation.setEndNavigable(panelAssociation.getChkNavigable2().isSelected());
						linkAssociation.setRoleNameStart((String)panelAssociation.getTxtRoleName1().getText());
						linkAssociation.setRoleNameEnd((String)panelAssociation.getTxtRoleName2().getText());
						setVisible(false);
			}
		});
		 btnOkDialog.setAlignmentX( 
				Component.CENTER_ALIGNMENT); 
		panSouth.add(Box.createVerticalGlue()); 
		panSouth.add(btnOkDialog); 
		panSouth.add(Box.createVerticalGlue());;
		add(panSouth, BorderLayout.SOUTH);
		
		pack();
	}
	
	
}
